<?php
namespace App\Admin\Controllers\Traits\WxSettingTraits;


use App\Wen\Utils\GatewayUtils;
use App\Wen\Utils\Settings;
use App\Wen\Utils\SiteUtils;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Widgets\Form;
use Dcat\Admin\Widgets\Tooltip;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;

trait formSeoTrait{
    public function index_seo(Content $content)
    {
        return $content->title('SEO')
//            ->body($this->buildPreviewButton())
//            ->body($this->newline())
            ->body(
                <<<HTML
<div class="card">{$this->form_seo()->render()}</div>
HTML
            );
    }
    protected function form_seo(){
        $form = new Form();
        $form->confirm('您确定要提交表单吗？', 'content');
        $form->disableResetButton();

        $form->tab('推送', function (Form $form) {
            $res10 = __system__paycode__tip__(10);
            Tooltip::make('.mini_global_admin_open_not_support_tip')
                ->bottom()
                ->title($res10['tip']);
            $form->text('seo_push_baidu_token', '百度推送token')->help($res10['text'].'进入<a href="https://ziyuan.baidu.com/" target="_blank">百度搜素资源平台</a>，点击查看<a href="https://img.mini.minisns.cn/images/seo/baidu_token_push.jpg" target="_blank">配置教程</a>')->default(Settings::get('seo_push_baidu_token', ''));
        });

        $form->action('settings/action/seo');
        return $form;
    }

    public function seo(Request $request)
    {
        SiteUtils::forget_config_data();
        Settings::set('seo_push_baidu_token', $request->input('seo_push_baidu_token'), true);

        $__global_config_version__ = Settings::get('__global_config_version__', 1) + 1;
        Settings::set('__global_config_version__', $__global_config_version__);
        GatewayUtils::success('all', 13, [ 'version' => $__global_config_version__, 'file' => basename(__FILE__) ]);
        return $this->response()->success('成功！');
    }
}
